

import java.io.Serializable;

public class CompteCourant extends CompteBancaire implements Serializable
{
	private static final long serialVersionUID = 6687130754395242052L;
	
	private	boolean m_cloture;
	private long m_numero;
	private Banque m_banque;

	public CompteCourant() {
		super();
		m_cloture= false;
		m_numero= 0;
	}

	public CompteCourant(final Banque b, final Titulaire t) throws IPException{
		super(b, t);
		m_cloture= false;
		m_numero= b.getCc();
		m_banque= b;
	}

	public long getNumeroCompte() {
		return m_numero;
	}

	public boolean getCloture()
	{
		return m_cloture;
	}

	public float executer(final String intitule, final char type, float montant) 
		throws BUException, IPException
	{
		return executer(new OperationBancaire(m_banque, type, intitule, montant));
	}

	public float executer(OperationBancaire op) throws BUException, IPException
	{
		if (m_cloture)
			throw new BUException("Ne peut pas executer d'operation bancaire sur" +
					" un compte cloture");
		 return super.executer(op);
	}
	
	public float cloturer() throws BUException
	{
		if (m_cloture)
			throw new BUException("compte deja cloture");
		float resultat = getSoldeCompte();
		try{
			executer("Fermeture du compte", 'R', resultat);
		} catch (IPException e) {}
		m_cloture= true;
		return resultat;
	}

	public Object clone() throws CloneNotSupportedException
	{
		throw new CloneNotSupportedException();
	}

	public boolean equals(Object o)
	{
		if (o == null)
			return false;
		if (!super.equals(o))
			return false;
		return m_numero == ((CompteCourant)o).getNumeroCompte() &&
				m_cloture == ((CompteCourant)o).getCloture();
	}
}
